Repository navigation
Read refs in YAML values of the files that the config names - #1
Conversation
In a YAML file that the new `yaml-values` key of the config file names,
a value that is one ref counts as a ref, plain or quoted, on one line,
also as an item of a `[...]` or `{...}` collection:
spec: sync:/docs/auth.md#token-lifetime
- "iref:/docs/auth.md"
specs: [sync:/docs/auth.md, sync:/docs/api.md]
A ref inside a longer value, in a `|` or `>` block, or in a plain value
that goes on in the next line is still not a ref. `,`, `[`, `{`, `]`
and `}` end a value only inside a collection, so the ref in
`note: Tokens, sync:/docs/auth.md` is not a value. Comments count as
before, in every file.
- The lexer can also return the string tokens of a file, so that a
quoted value that holds only the ref is told from a longer string.
- `findRefs` takes `values`, and `checkText` sets it from the config,
so the CLI and the extension both read the values.
- The README, the guide and the extension's README describe the key.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… to read Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mondaychen
left a comment
There was a problem hiding this comment.
I found 5 problems in the YAML-value refs. I checked each YAML case against the built core. Problems 1 and 2 are important, and I suggest that you fix them before this PR merges. Problems 3 to 5 are minor and can be follow-up work.
4 (minor). VS Code gives no completion in a YAML value (packages/vscode/src/features.ts:270, a file that this PR does not change, so I cannot comment on the line).
Completion.provideCompletionItems stops if the cursor is not in a commentSpans span. Links and diagnostics use checkText, so they work in YAML values. But completion does not, and the VS Code README now says that a value can be a ref.
Example: the config has yaml-values = ["model/**"]. In model/a.yaml, type spec: sync:/do. No completion items come. The same text in a # comment gives completions.
Possible fix: when repo.readsYamlValues(source) is true for a YAML file, also accept a cursor in a value. For example, use findRefs with values = true, or add a helper that returns the value spans.
| const before = text.slice(lineStart, start); | ||
| const after = text.slice(end, lineEnd); | ||
| if (flowAt(ref.start) !== undefined) return YAML_FLOW_VALUE.test(before) && YAML_FLOW_END.test(after); | ||
| if (!YAML_BLOCK_VALUE.test(before) || !YAML_BLOCK_END.test(after)) return false; |
There was a problem hiding this comment.
1 (important). A ref that is only the last line of a multi-line plain value is found.
The rule is that the ref must be the whole value. But here, interref reports a ref:
key: some text
- sync:/a.md
next: xYAML reads this as {key: "some text - sync:/a.md"}, so sync:/a.md is not the whole value. findRefs(..., true) still returns sync:/a.md. - some text followed by - sync:/b.md gives the same false ref.
The cause: YAML_BLOCK_VALUE tests only the text before the ref on its own line, and it accepts -. continues() checks the lines after the ref, but nothing checks the lines before it.
Possible fix: also look back. If an earlier plain scalar has not ended, and the line of the ref has more indentation than the key of that scalar, the line continues the scalar. Then reject the ref.
There was a problem hiding this comment.
Fixed by the parser. key: some text followed by - sync:/a.md is one value, so there is no
ref. Your two examples are now tests.
| const lineEnd = newline < 0 ? text.length : newline; | ||
| const before = text.slice(lineStart, start); | ||
| const after = text.slice(end, lineEnd); | ||
| if (flowAt(ref.start) !== undefined) return YAML_FLOW_VALUE.test(before) && YAML_FLOW_END.test(after); |
There was a problem hiding this comment.
2 (important). Items of a flow collection that goes across lines are not found.
This is a common list style:
specs: [
sync:/a.md,
sync:/b.md
]YAML reads this as two items, sync:/a.md and sync:/b.md. But findRefs(..., true) returns no refs, so a broken target in this list is not reported. The README and SKILL.md say that an item of a [...] or {...} collection counts.
The cause: YAML_FLOW_VALUE needs [, {, , or key: before the item on the same line. YAML_FLOW_END needs ,, ], } or a comment after the item on the same line. So an item at the start of a line fails, and the last item before a line break also fails.
Possible fix: in a flow collection, also accept an item that has only indentation before it on its line. Also accept the end of the line when the next line that is not blank starts with ,, ] or }.
There was a problem hiding this comment.
Fixed by the parser. specs: [, sync:/a.md,, sync:/b.md, ] gives both refs. This is a
test now.
| * Matches the text before a value in block context: one or more `- ` at the start of the line, or | ||
| * `key: `. | ||
| */ | ||
| const YAML_BLOCK_VALUE = /(?:^[ \t]*(?:-[ \t]+)+|[^\s:]:[ \t]+)$/u; |
There was a problem hiding this comment.
3 (minor). Some plain values on one line are not found.
YAML_BLOCK_VALUE needs key: or - directly before the ref, on the same line. So these two values are not found, although YAML reads each one as a whole value:
- A value on the line under its key:
key:and thensync:/c.mdon the next line. YAML gives{key: "sync:/c.md"}. - A value after an anchor or a tag:
key: &x sync:/f.mdorkey: !!str sync:/f.md.
Possible fix: accept a value that is alone on an indented line under a key: that has no value. Also let &anchor and !tag come before the value. If you prefer to keep this limit, write it in the README.
There was a problem hiding this comment.
Fixed by the parser: key: followed by sync:/c.md, key: &x sync:/f.md and
key: !!str sync:/f.md are refs. An alias (*x) is not counted a second time. The README lists
these cases.
| if (depth === 0) flows.push({ start, end: at + 1 }); | ||
| } | ||
| } | ||
| if (depth > 0) flows.push({ start, end: text.length }); |
There was a problem hiding this comment.
5 (minor). One [ or { without a close makes the rest of the file a flow collection.
When depth > 0 at the end of the text, this line adds a span to text.length. After that, every block value is tested with the flow rules, and every comma becomes a space.
Example:
title: [draft
k: sync:/e.mdThis can come from a typo or from a template line. findRefs(..., true) returns no refs. So the valid value k: sync:/e.md, and all later refs in the file, are not checked.
Possible fix: end a flow collection that has no close at the first later line that does not have more indentation than the line where the collection started. Or skip a collection that has no close.
There was a problem hiding this comment.
Fixed by the parser. The parser reports an error, but it still reads the later values, so
k: sync:/e.md after title: [draft is found. This is a test now.
|
If we do want this, I recommend using a real YAML parser in place of the regex rules. The yaml (https://www.npmjs.com/package/yaml) package is a good choice: it is well maintained and has no dependencies of its own. Why the current approach has these bugsTo know whether a ref is the whole value, interref must know where each YAML value starts and ends. The PR finds this with regexes that look at one line at a time. But YAML values can go across lines:
The 5 problems in the review all come from this gap. A fix for each one adds more rules, and other YAML cases will still be missing. The |
…in VS Code The review of the YAML values asked for a real YAML parser in place of the regex rules. These rules look at one line at a time, but a YAML value can go across lines, and the 5 problems that the review found all come from this gap. `packages/core/src/values.ts` now reads a file that `yaml-values` names with the `yaml` package. A plain or quoted scalar that is not a key, and whose text is exactly one ref, is a ref. The lexer still finds the comments, as before, and no longer returns the string tokens. - A plain value that continues the line before it, as ` - sync:/a.md` under `key: some text`, is not a ref. - A `[...]` list that goes across lines gives each of its refs. - A value on the line under its key, or after an anchor or a tag (`key: &x sync:/a.md`, `key: !!str sync:/a.md`), is a ref. An alias does not count the ref a second time. - A `[` that is not closed no longer hides the later values of the file. - In VS Code, completion also works for a ref that starts a value. A key counts too, because a ref that is still being typed, such as `- sync:`, reads as a key. `yaml` (ISC) has no dependencies of its own. esbuild bundles it into the CLI and the extension. `yaml` is CommonJS, so the ES module bundle of the CLI makes a `require` for it. Its license is in the new THIRD-PARTY-NOTICES, which the npm package and the .vsix ship next to LICENSE. The README, the guide, the extension's README and DEVELOPMENT.md describe the parser and the cases that are not refs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the review. Both branches are updated: Use a real YAML parser Done. The regex rules are gone. Your commit that rewrote the comments and docs stays as it is, and the fixes are a new commit after
Item 4: completion in a YAML value Fixed. In a file that |
- A completion or a quick fix that puts a path into a `[...]` list no longer breaks the list when the file name has a `,`. `encodeRefPath` now writes `,` as `%2C`. This also keeps a `,` at the end of a file name, which the scanner dropped as punctuation. - A quoted value with no closing quote at the end of the file is not a ref. Before, the parser dropped the last character of the path, so `a: 'sync:/docs/auth.md` gave the ref `sync:/docs/auth.m`. - Completion in a YAML value reads the ref from the start of the value that the cursor is in. Thus `[sync:/a.md,sync:/]` now gives paths for the second item, and `key: (sync:/` gives no paths, since the value that it makes is not a ref. `valueStartAt` replaces `valueSpans`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In a YAML file that the new
yaml-valueskey of the config file names,a value that is one ref counts as a ref. The value can be plain or
quoted, and it can be an item of a
[...]or{...}collection:The
yamlpackage reads these files, so a value can also be on the lineunder its key, come after an anchor or a tag, or be an item of a list
that goes across lines. Comments count as before, in every file.
These values are not refs:
note: Tokens, sync:/docs/auth.md.|or>block.line before it.
Changes
packages/core/src/values.tsfinds the refs in YAML values with theyamlparser.findRefstakesvalues, andcheckTextsets it fromthe config, so the CLI and the extension both read the values.
the ref from the start of the value that the cursor is in.
encodeRefPathalso encodes,as%2C, so a completion or a quickfix in a
[...]list does not split the list.yaml(ISC) has no dependencies of its own. esbuild bundles it intothe CLI and the extension. Its license is in the new
THIRD-PARTY-NOTICES, which the npm package and the .vsix ship next to
LICENSE.
describe the key, the parser, and the cases that are not refs.
Tests
72 core and 21 CLI tests pass. Lint is clean.
pnpm verify-commentsshows no disagreement. The VS Code package has no tests; a script
checked the completion cases against the built core.
🤖 Generated with Claude Code